<template>
  <div id="Test">
    <h2 style="text-align: center">入库申请登记</h2>
    <div class="panel-heading" style="text-align: right">
<!--      <el-button type="info" @click="jisuan">添加商品</el-button>-->
      <el-button type="warning" @click="jisuan">预览</el-button>
      <el-button type="success" @click="addbtn">确定</el-button>
      <el-button type="primary"><a href="javascript:history.back()"
                                   style="color: black">返回</a></el-button>
    </div>
    <el-form :inline="true" :model="info" class="demo-form-inline">
      <el-form-item label="入库人:">
        <el-input v-model="info.storer" placeholder="入库人"></el-input>
      </el-form-item>
      <el-form-item label="入库理由:">
        <el-input v-model="info.reason" placeholder="R001-1（采购入库）"></el-input>
      </el-form-item>
      <el-form-item label="总数量:">
        <el-input v-model="info.totalAmount" placeholder="总数量"></el-input>
      </el-form-item>

      <el-form-item label="总价格:">
        <el-input v-model="info.totalPrice" placeholder="总价格"></el-input>
      </el-form-item>
      <el-form-item label="申请人:">
        <el-input v-model="info.register" placeholder="申请人"></el-input>
      </el-form-item>
      <el-form-item label="申请时间:">
        <el-input v-model="info.registeTime | formatDate" placeholder="申请时间"></el-input>
      </el-form-item>
      <el-form-item label="审核理由:">
        <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="info.checkReason">
        </el-input>
      </el-form-item>
    </el-form>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          prop="gatherId"
          label="入库单id"
          width="180">
      </el-table-column>
      <el-table-column
          prop="amount"
          label="数量"
          width="180">
      </el-table-column>
      <el-table-column
          prop="stockId"
          label="仓库id">
      </el-table-column>
      <el-table-column
          prop="price"
          label="单价">
      </el-table-column>
      <el-table-column
          prop="subTotal"
          label="小计">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  created() {
    this.list2();
    this.getdatatime();
  },
  data() {
    return {
      info: {

      },
      textarea: '',
      input: '',
      tableData: {},
    }
  },
  methods: {
    getdatatime() {
      // 创建一个 Date 对象
      const currentDate = new Date();
      console.log('currentDate++',currentDate)
      // 将当前时间赋给你想要更新的时间属性
      this.info.registeTime = currentDate;
    },
    async addGather() {
      const { data: res } = await this.$http.post
      (`/community/gather/add`,this.info)
      this.info = res
    },
    async list2() {
      const res = await this.$http.get
      (`/community/gatherDetails/show2`)
      console.log('res',res)
      this.tableData = res.data
    },
    async jisuan() {

    },
    async addbtn() {
      let gather_details = this.tableData
      let gather = this.info
      let module_dto ={
        gather_details,
        gather
      }
      const res = await this.$http.post
      (`/community/gather/add`,module_dto)
      console.log('res',res)
      if(res.data.status == 200){
        alert('添加成功')
      }
    },
  },
  filters: {
    formatDate(date) {
      var dt = new Date(date);
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, '0');
      var d = dt.getDate().toString().padStart(2, '0');
      var hh = dt.getHours().toString().padStart(2, '0');
      var mm = dt.getMinutes().toString().padStart(2, '0');
      var ss = dt.getSeconds().toString().padStart(2, '0');
      return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    }
  }

}
</script>

<style scoped>

</style>